<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <crudOperation :permission="permission">
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="primary"
          @click="submit()"
        >
          保存
        </el-button>
        <el-button
          v-if="crud.optShow.pass"
          v-permission="crud.optShow.pass"
          class="filter-item"
          salesPromotion
          size="mini"
          type="success"
          :disabled="crud.selections.length < 1"
          @click="crud.enableOrDisable('PASS', crud.order.id)"
        >
          审核
        </el-button>
        <el-button
          slot="right"
          v-if="crud.order.orderStatus !== 'PASS'"
          class="filter-item"
          size="mini"
          type="success"
          @click="recover('RECOVER')"
        >
          恢复
        </el-button>
        <el-button
          slot="right"
          v-if="crud.order.orderStatus !== 'PASS'"
          class="filter-item"
          size="mini"
          type="danger"
          @click="recover('INVALID')"
        >
          作废
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="danger"
          @click="crud.toCopy($route.params.id, '/sale/salesPromotionDetail')"
        >
          复制
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="danger"
          @click="showExceptCustomer = true"
        >
          例外客户
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          v-if="crud.order.customerGroupType === 2"
          type="danger"
          @click="showCustomerGroup = true"
        >
          客户群
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-form
        ref="form"
        :model="crud.order"
        :rules="rules"
        size="small"
        label-width="100px"
      >
        <el-divider content-position="left">基本信息</el-divider>
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item label="促销编码" prop="code">
              <el-input
                v-model="crud.order.code"
                disabled
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="促销名称" prop="name">
              <el-input
                v-model="crud.order.name"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="业务日期">
              <el-date-picker
                v-model="crud.order.busDate"
                type="date"
                style="width:  100%"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="请选择"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态">
              <el-select
                v-model="crud.order.orderStatus"
                disabled
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.common_order_status"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始日期" prop="startDate">
              <el-date-picker
                v-model="crud.order.startDate"
                type="datetime"
                style="width:  100%"
                format="yyyy-MM-dd HH:mm:ss"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="结束日期" prop="endDate">
              <el-date-picker
                v-model="crud.order.endDate"
                type="datetime"
                style="width:  100%"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="请选择"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="优先级">
              <el-input
                v-model="crud.order.level"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动属性">
              <el-select
                v-model="crud.order.promotionProperties"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                class="edit-input"
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item,
                  index) in dict.t_sales_promotion_promotion_properties"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户群类型" prop="customerGroupType">
              <el-select
                v-model="crud.order.customerGroupType"
                @change="changeInfo"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                class="edit-input"
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item,
                  index) in dict.t_sales_promotion_customer_group_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="渠道类型">
              <el-select
                v-model="crud.order.channelType"
                clearable
                class="edit-input"
                placeholder="请选择"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.t_bas_customer_channel_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="crud.order.customerGroupType != 1">
            <!--            <el-form-item label="客户" v-if="crud.order.customerGroupType == 2">-->
            <!--              <zSelect  multiple  :disabled="crud.order.orderStatus === 'PASS' || crud.order.orderStatus === 'INVALID'"  :value.sync="crud.order.customerId" :showName="crud.order.customerName" url="api/dropDown/basCustomerList" :params="{businessAttr:'3'}" style="width:  100%" />-->
            <!--            </el-form-item>-->
            <el-form-item
              label="客户分类"
              v-if="crud.order.customerGroupType == 3"
            >
              <JtgTree
                multiple
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                v-model="customerTypeIds"
                :initValue="crud.order.customerTypeName"
                :keyword="crud.order.customerTypeName"
                url="basCustomerTypeTree"
              />
            </el-form-item>
            <el-form-item
              label="客户区域"
              v-if="crud.order.customerGroupType == 4"
            >
              <JtgTree
                multiple
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                v-model="customerAreaIds"
                :initValue="crud.order.customerAreaName"
                :keyword="crud.order.customerAreaId"
                url="basCustomerAreaTree"
              />
            </el-form-item>
            <el-form-item
              label="销售体系"
              v-if="crud.order.customerGroupType == 5"
            >
              <zSelect
                multiple
                :value.sync="saleSystemIds"
                :showName="saleSystemName"
                url="api/dropDown/basSaleSystemList"
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="档期">
              <el-input
                v-model="crud.order.schedule"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否互斥">
              <el-select
                v-model="crud.order.isMutex"
                class="edit-input"
                placeholder="请选择"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.common_yes_or_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否重复参加">
              <el-select
                v-model="crud.order.isRepeatJoin"
                class="edit-input"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.common_yes_or_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否限制数量">
              <el-select
                v-model="crud.order.isLimitCount"
                class="edit-input"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.common_yes_or_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="促销限制数量">
              <el-input
                v-model="crud.order.promotionLimitCount"
                :disabled="
                  crud.order.isLimitCount == 0 ||
                    crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width: 100%;"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否限制平台">
              <el-select
                v-model="crud.order.isLimitChannel"
                class="edit-input"
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.common_yes_or_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="平台">
              <el-select
                v-model="crud.order.channel"
                class="edit-input"
                :disabled="
                  crud.order.isLimitChannel == 0 ||
                    crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.t_sales_promotion_channel_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="促销类型" prop="type">
              <el-select
                v-model="crud.order.type"
                :disabled="crud.order.id"
                class="edit-input"
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in dict.t_sales_promotion_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="crud.order.type === 1">
            <el-form-item label="特价类型" prop="promotionSpecialType">
              <el-select
                v-model="crud.order.promotionSpecialType"
                :disabled="!crud.order.orderStatus === 'PASS'"
                class="edit-input"
                placeholder="请选择"
                style="width:  100%"
              >
                <el-option
                  v-for="(item, index) in specialTypeList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="是否往来">-->
          <!--              <el-select v-model="crud.order.isContact" :disabled="crud.order.orderStatus === 'PASS' || crud.order.orderStatus === 'INVALID'"  class="edit-input" disabled placeholder="请选择"      style="width:  100%">-->
          <!--                <el-option-->
          <!--                  v-for="(item,index) in dict.t_bas_customer_is_contact"-->
          <!--                  :key="index"-->
          <!--                  :label="item.label"-->
          <!--                  :value="item.value"-->
          <!--                />-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="供应商分类">-->
          <!--              <JtgTree-->
          <!--                v-model="query.customerTypeId"-->
          <!--                :initValue="query.customerTypeName"-->
          <!--                :keyword="query.customerTypeName"-->
          <!--                url="basCustomerTypeTree"-->
          <!--              />-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="供应商区域" prop="customerAreaId">-->
          <!--              <JtgTree-->
          <!--                v-model="query.customerAreaId"-->
          <!--                :initValue="query.customerAreaName"-->
          <!--                :keyword="query.customerAreaId"-->
          <!--                url="basCustomerAreaTree"-->
          <!--              />-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="销售体系">-->
          <!--              <el-input v-model="crud.order.saleSystemName" disabled style="width: 100%;"/>-->
          <!--              &lt;!&ndash;            <zSelect :value.sync="form.saleSystemId" url="api/dropDown/basSaleSystemList"&ndash;&gt;-->
          <!--              &lt;!&ndash;                     style="width:  370px"/>&ndash;&gt;-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="OA编号">-->
          <!--              <el-input v-model="crud.order.oaCode"   style="width:  100%"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="促销规则方式">-->
          <!--              <el-select v-model="crud.order.ruleWay" class="edit-input" placeholder="请选择"        style="width:  100%">-->
          <!--                <el-option-->
          <!--                  v-for="(item,index) in dict.t_sales_promotion_promotion_properties"-->
          <!--                  :key="index"-->
          <!--                  :label="item.label"-->
          <!--                  :value="item.value"-->
          <!--                />-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->

          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="促销剩余数量">-->
          <!--              <el-input v-model="crud.order.promotionRemainCount" style="width: 100%;"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->

          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="人员名称">-->
          <!--              <zSelect :value.sync="crud.order.userId" url="api/dropDown/sysUserList"       style="width:  100%"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="排序">-->
          <!--              <el-input-number v-model="crud.order.seq" :min="1" label="排序"    style="width:  100%"></el-input-number>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="单据状态">-->
          <!--              <el-select v-model="crud.order.orderStatus"  placeholder="请选择" style="width:  100%">-->
          <!--                <el-option-->
          <!--                  v-for="(item,index) in dict.common_order_status"-->
          <!--                  :key="index"-->
          <!--                  :label="item.label"-->
          <!--                  :value="item.value"-->
          <!--                />-->
          <!--              </el-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="单据说明">-->
          <!--              <el-input v-model="crud.order.orderRemark"  style="width:  100%"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="部门名称">-->
          <!--              <JtgTree-->
          <!--                v-model="crud.order.deptId"-->
          <!--                :initValue="crud.order.deptName"-->
          <!--                :keyword="crud.order.deptId"-->
          <!--                url="childSysDeptList"-->
          <!--              />-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--          <el-col :span="6" v-show="crud.order.customerGroupType !== 2">-->
          <!--          <el-form-item label="例外客户" >-->
          <!--            <zSelect-->
          <!--              url="api/dropDown/basCustomerList"-->
          <!--              :disabled="crud.order.orderStatus === 'PASS' || crud.order.orderStatus === 'INVALID'"-->
          <!--                        :value.sync="crud.order.exceptCustomerIds"-->
          <!--                        :showName.sync="crud.order.exceptCustomerName"-->
          <!--                        multiple-->
          <!--                        clearable-->
          <!--                        :params="{businessAttr:'3'}" style="width:  100%" />-->
          <!--          </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="6">
            <el-form-item label="参与次数">
              <el-input
                v-model="crud.order.joinCount"
                disabled
                style="width:  100%"
              />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="备注">
              <el-input
                v-model="crud.order.remark"
                type="textarea"
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col v-if="crud.order.promotionProperties === 3" :span="6">
            <el-form-item label="代垫比例">
              <el-input
                v-model="crud.order.advanceRate"
                @change="changeRate('advanceRate')"
                oninput="value=value.replace(/[^\d^\.]/g,'')"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="crud.order.promotionProperties === 3">
            <el-form-item label="自费比例">
              <el-input
                v-model="crud.order.expenseRate"
                @change="changeRate('expenseRate')"
                :disabled="
                  crud.order.orderStatus === 'PASS' ||
                    crud.order.orderStatus === 'INVALID'
                "
                style="width:  100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left" style="width:  100%"
          >活动选择</el-divider
        >

        <el-row>
          <el-col :span="8">
            <el-form-item label="促销类型" prop="type">
              <!--            <el-select v-model="form.type" class="edit-input" placeholder="请选择" style="width:  370px;">-->
              <!--              <el-option-->
              <!--                  v-for="(item,index) in dict.t_sales_promotion_type"-->
              <!--                  :key="index"-->
              <!--                  :label="item.label"-->
              <!--                  :value="item.value"-->
              <!--              />-->
              <!--            </el-select>-->
              <el-radio-group v-model="crud.order.type" style="width:  100%">
                <el-radio-button
                  :label="item.value"
                  v-if="item.value == crud.order.type"
                  v-for="(item, index) in dict.t_sales_promotion_type"
                  :key="index"
                >
                  {{ item.label }}
                </el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <div class="group" v-if="crud.order.type == 1">
            <div>
              <H3>活动商品列表</H3>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="toAdd"
              >
                新增
              </el-button>
            </div>
            <el-table
              ref="tableA"
              stripe
              border
              v-if="crud.order.type == 1"
              v-loading="crud.loading"
              :row-class-name="crud.tableRowClassName"
              :data="specialList || []"
              size="small"
              style="width: 100%;"
              :show-summary="true"
              sortable="custom"
              @sort-change="crud.sortChange"
              @selection-change="crud.selectionChangeHandler"
              @row-dblclick="tabSelect"
            >
              <el-table-column
                :render-header="crud.renderHeader"
                type="selection"
                width="60"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                type="index"
                width="60"
                label="序号"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsCode')"
                prop="goodsCode"
                label="商品编码"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsName')"
                prop="goodsName"
                label="商品名称"
                width="200"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.goodsName
                  }}</span>
                  <jtg-select-plus
                    v-else
                    ref="productRef"
                    v-model="scope.row.goodsId"
                    :initValue="scope.row.goodsName"
                    type="1"
                    :customerId="crud.order.customerId"
                    :buyChannel="crud.order.buyChannel"
                    @remoteMethod="getValue($event, scope.$index)"
                    @change="crud.productChange($event, scope)"
                    url="productList"
                  />
                </template>
              </el-table-column>
              <!--              <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxPrice')" prop="taxPrice" label="含税单价" >-->
              <!--                <template slot-scope="scope">-->
              <!--                  <span v-if="!scope.row.isSelected">{{ scope.row.taxPrice }}</span>-->
              <!--                  <el-input v-if="scope.row.isSelected"-->
              <!--                            oninput="value=value.replace(/[^\d^\.]/g,'')"-->
              <!--                            maxlength="12"-->
              <!--                            v-model.lazy="scope.row.taxPrice"-->
              <!--                            style="width: 100%"/>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('barcode')"
                prop="barcode"
                label="条形码"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('boxUnitCount')"
                prop="boxUnitCount"
                label="箱装量"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('saleTaxPrice')"
                prop="saleTaxPrice"
                label="零售价"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.saleTaxPrice }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('oldTaxPrice')"
                prop="oldTaxPrice"
                label="原价"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.oldTaxPrice }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('promotionTaxPrice')"
                prop="promotionTaxPrice"
                label="促销价"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.promotionTaxPrice
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    maxlength="12"
                    @input.native="inputCount(scope, 'promotionTaxPrice')"
                    v-model.lazy="scope.row.promotionTaxPrice"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('promotionTaxBoxPrice')"
                prop="promotionTaxBoxPrice"
                label="促销箱价"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.promotionTaxBoxPrice
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    maxlength="12"
                    @input.native="inputCount(scope, 'promotionTaxBoxPrice')"
                    v-model.lazy="scope.row.promotionTaxBoxPrice"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('remark')"
                prop="remark"
                label="备注"
                width="200"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.remark
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    type="textarea"
                    :rows="2"
                    v-model.lazy="scope.row.remark"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                label="操作"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    slot="reference"
                    class="el-icon-delete opration_icon_btn"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    style="border: none;width: auto;height: auto"
                    @click="delAddRow('specialList', scope.$index)"
                  ></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="group" v-if="crud.order.type == 2">
            <div>
              <H3>活动商品列表</H3>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="toAdd"
              >
                新增
              </el-button>
            </div>
            <el-table
              ref="tableB"
              stripe
              border
              v-if="crud.order.type == 2"
              v-loading="crud.loading"
              :row-class-name="crud.tableRowClassName"
              :data="bomList || []"
              size="small"
              style="width: 100%;"
              :show-summary="true"
              sortable="custom"
              @sort-change="crud.sortChange"
              @selection-change="crud.selectionChangeHandler"
              @row-dblclick="crud.dbClick"
            >
              <el-table-column
                :render-header="crud.renderHeader"
                type="selection"
                width="60"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                type="index"
                width="60"
                label="序号"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsCode')"
                prop="goodsCode"
                label="商品编码"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsName')"
                prop="goodsName"
                label="商品名称"
                width="200"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.goodsName
                  }}</span>
                  <jtg-select-plus
                    v-else
                    ref="productRef"
                    v-model="scope.row.goodsId"
                    type="1"
                    :customerId="crud.order.customerId"
                    :initValue="scope.row.goodsName"
                    :buyChannel="crud.order.buyChannel"
                    @remoteMethod="getValue($event, scope.$index)"
                    @change="crud.productChange($event, scope)"
                    url="productList"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('firstUnitName')"
                prop="firstUnitName"
                label="计量单位"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsCount')"
                prop="goodsCount"
                label="数量"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.goodsCount
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    maxlength="12"
                    @input.native="crud.inuptCount(scope, 'taxPrice')"
                    v-model.lazy="scope.row.goodsCount"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('boxCount')"
                prop="boxCount"
                label="箱数"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('taxPrice')"
                prop="taxPrice"
                label="含税单价"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.taxPrice
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    maxlength="12"
                    @input.native="crud.inuptCount(scope, 'taxPrice')"
                    v-model.lazy="scope.row.taxPrice"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('taxAmount')"
                prop="taxAmount"
                label="含税金额"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.taxAmount }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('taxPrice')"
                prop="taxPrice"
                label="含税单价"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.taxPrice }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('taxBoxPrice')"
                prop="taxBoxPrice"
                label="含税箱价"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.taxBoxPrice }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('tax')"
                prop="tax"
                label="税额"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.tax }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('remark')"
                prop="remark"
                label="备注"
                width="200"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.remark
                  }}</span>
                  <el-input
                    v-if="scope.row.isSelected"
                    type="textarea"
                    :rows="2"
                    v-model.lazy="scope.row.remark"
                    style="width: 100%"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                label="操作"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    slot="reference"
                    class="el-icon-delete opration_icon_btn"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    style="border: none;width: auto;height: auto"
                    @click="delAddRow('bomList', scope.$index)"
                  ></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="group" v-if="crud.order.type == 3">
            <el-row>
              <el-col :span="6">
                <el-form-item label="达成类型">
                  <el-select
                    v-model="crud.data.ruleList[0].reachType"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    @change="pushInfo"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_type"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="满赠方式">
                  <el-select
                    v-model="crud.data.ruleList[0].reachWay"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    @change="pushInfo"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_way"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="满赠方式" v-if="isShow">
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 1">
                  <div>
                    <el-checkbox v-model="checked" disabled>阶梯</el-checkbox>
                  </div>
                  <div class="flex-left">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        placeholder="请输入"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        @change="
                          val => {
                            isNum(item, index);
                          }
                        "
                        @input="changeInput"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        placeholder="请输入"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        @change="isGiftNum(item, index)"
                        @input="changeInput"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >赠</template
                        >
                      </el-input>
                      <el-select
                        v-model="crud.data.ruleList[index].resultType"
                        @input="changeInput"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        class="edit-input"
                        placeholder="请选择"
                        style="width: 80px"
                      >
                        <el-option
                          v-for="(item, index) in resultList"
                          :key="index"
                          :label="item.label"
                          :value="item.value"
                        />
                      </el-select>
                      <img
                        src="@/assets/images/add@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS'"
                        @click="handleAdd"
                        style="width: 30px;cursor: pointer"
                      />
                      <img
                        src="@/assets/images/delete@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS' && index !== 0"
                        @click="handledel(index)"
                        style="width: 30px;cursor: pointer"
                      />
                    </div>
                  </div>
                </el-col>
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 2">
                  <div>
                    <el-checkbox v-model="checked" disabled>每满</el-checkbox>
                  </div>
                  <div class="flex-right">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >赠</template
                        >
                      </el-input>
                      <el-select
                        v-model="crud.data.ruleList[index].resultType"
                        @change="$event => setResultType(index, $event)"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        class="edit-input"
                        placeholder="请选择"
                        style="width: 80px"
                      >
                        <el-option
                          v-for="(item, index) in resultList"
                          :key="index"
                          :label="item.label"
                          :value="item.value"
                        />
                      </el-select>
                    </div>
                  </div>
                </el-col>
              </el-form-item>
            </el-row>
            <div>
              <H3>活动商品列表</H3>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="toAdd"
              >
                新增
              </el-button>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="showAddBatch = true"
              >
                批量新增
              </el-button>
            </div>
            <el-dialog
              :close-on-click-modal="false"
              title="批量新增"
              :visible.sync="showAddBatch"
              append-to-body
              width="100vw"
            >
              <add-batch
                v-if="showAddBatch"
                :showAddBatchDialog.sync="showAddBatch"
                @change="addBatchGoods"
              ></add-batch>
            </el-dialog>
            <el-tabs
              v-model="activeName"
              type="card"
              v-if="crud.order.type == 3"
            >
              <el-tab-pane label="活动商品" name="activity">
                <el-table
                  ref="tableC"
                  stripe
                  border
                  v-loading="crud.loading"
                  :row-class-name="crud.tableRowClassName"
                  :data="activityList || []"
                  size="small"
                  style="width: 100%;"
                  :show-summary="true"
                  sortable="custom"
                  @sort-change="crud.sortChange"
                  @selection-change="crud.selectionChangeHandler"
                  @row-dblclick="tabSelect"
                >
                  <el-table-column
                    :render-header="crud.renderHeader"
                    type="selection"
                    width="60"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    type="index"
                    width="60"
                    label="序号"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsCode')"
                    prop="goodsCode"
                    label="商品编码"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsName')"
                    prop="goodsName"
                    label="商品名称"
                    width="200"
                  >
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isSelected">{{
                        scope.row.goodsName
                      }}</span>
                      <jtg-select-plus
                        v-else
                        ref="productRef"
                        v-model="scope.row.goodsId"
                        type="1"
                        :customerId="crud.order.customerId"
                        :initValue="scope.row.goodsName"
                        :buyChannel="crud.order.buyChannel"
                        @remoteMethod="getValue($event, scope.$index)"
                        @change="crud.productChange($event, scope)"
                        url="productList"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('helpSign')"
                    prop="helpSign"
                    label="助记符"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.helpSign }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('model')"
                    prop="model"
                    label="规格型号"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.model }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('isRequired')"
                    prop="isRequired"
                    label="是否必选"
                  >
                    <template slot-scope="scope">
                      <el-select
                        v-model="scope.row.isRequired"
                        :disabled="crud.order.orderStatus === 'PASS'"
                        class="edit-input"
                        placeholder="是否必选"
                        style="width: 100%;"
                      >
                        <el-option
                          v-for="(item, index) in dict.common_yes_or_no"
                          :key="index"
                          :label="item.label"
                          :value="item.value"
                        />
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('barcode')"
                    prop="barcode"
                    label="条形码"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.barcode }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsBrandName')"
                    prop="goodsBrandName"
                    label="商品品牌"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.goodsBrandName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsTypeName')"
                    prop="goodsTypeName"
                    label="商品分类"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.goodsTypeName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('firstUnitName')"
                    prop="firstUnitName"
                    label="单位"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.firstUnitName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsCount')"
                    prop="goodsCount"
                    label="满足数量"
                  >
                    <template slot-scope="scope">
                      <!-- <span>{{scope.row.goodsCount}}</span> -->
                      <el-input v-model="scope.row.goodsCount" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    label="操作"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-button
                        class="el-icon-delete opration_icon_btn"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        style="border: none;width: auto;height: auto"
                        @click="delAddRow('activityList', scope.$index)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
              <el-tab-pane label="赠品" name="gift">
                <el-table
                  ref="tableB"
                  stripe
                  border
                  v-loading="crud.loading"
                  :row-class-name="crud.tableRowClassName"
                  :data="giftList01 || []"
                  size="small"
                  style="width: 100%;"
                  :show-summary="true"
                  sortable="custom"
                  @sort-change="crud.sortChange"
                  @selection-change="crud.selectionChangeHandler"
                  @row-dblclick="tabSelect"
                >
                  <el-table-column
                    :render-header="crud.renderHeader"
                    type="selection"
                    width="60"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    type="index"
                    width="60"
                    label="序号"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsCode')"
                    prop="goodsCode"
                    label="商品编码"
                  />
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsName')"
                    prop="goodsName"
                    label="商品名称"
                    width="200"
                  >
                    <template slot-scope="scope">
                      <span v-if="!scope.row.isSelected">{{
                        scope.row.goodsName
                      }}</span>
                      <jtg-select-plus
                        v-else
                        ref="productRef"
                        v-model="scope.row.goodsId"
                        type="1"
                        :customerId="crud.order.customerId"
                        :initValue="scope.row.goodsName"
                        :buyChannel="crud.order.buyChannel"
                        @remoteMethod="getValue($event, scope.$index)"
                        @change="productChange($event, scope)"
                        url="productList"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('helpSign')"
                    prop="helpSign"
                    label="助记符"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.helpSign }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('model')"
                    prop="model"
                    label="规格型号"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.model }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('barcode')"
                    prop="barcode"
                    label="条形码"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.barcode }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsBrandName')"
                    prop="goodsBrandName"
                    label="商品品牌"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.goodsBrandName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsTypeName')"
                    prop="goodsTypeName"
                    label="商品分类"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.goodsTypeName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('expenseRate')"
                    prop="expenseRate"
                    label="自费比例"
                  >
                    <template slot-scope="scope">
                      <el-input
                        v-if="crud.order.promotionProperties === 3"
                        v-model="scope.row.expenseRate"
                      />
                      <span v-else>{{ scope.row.expenseRate }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('advanceRate')"
                    prop="advanceRate"
                    label="代垫比例"
                  >
                    <template slot-scope="scope">
                      <el-input
                        v-if="crud.order.promotionProperties === 3"
                        v-model="scope.row.advanceRate"
                        oninput="value=value.replace(/[^\d^\.]/g,'')"
                      />
                      <span v-else>{{ scope.row.advanceRate }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('firstUnitName')"
                    prop="firstUnitName"
                    label="单位"
                  >
                    <template slot-scope="scope">
                      <span>{{ scope.row.firstUnitName }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('isGiftPaperBox')"
                    prop="isGiftPaperBox"
                    label="商品类型"
                  >
                    <template slot-scope="scope">
                      <zSelect
                        collapseTags
                        :value.sync="scope.row.goodsTagId"
                        :showName="scope.row.goodsTagName"
                        url="api/dropDown/basGoodsTagList"
                        style="width: 100%;"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('isGiftPaperBox')"
                    prop="isGiftPaperBox"
                    label="是否赠箱"
                  >
                    <template slot-scope="scope">
                      <el-select
                        v-model="scope.row.isGiftPaperBox"
                        :disabled="crud.order.orderStatus === 'PASS'"
                        class="edit-input"
                        placeholder="请选择是否赠箱"
                        style="width: 100%;"
                      >
                        <el-option
                          v-for="(item, index) in dict.common_yes_or_no"
                          :key="index"
                          v-if="item.seq > 0"
                          :label="item.label"
                          :value="item.value"
                        />
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    v-if="columns.visible('goodsCount')"
                    prop="goodsCount"
                    label="必填数量"
                  >
                    <template slot-scope="scope">
                      <!-- <span>{{scope.row.goodsCount}}</span> -->
                      <el-input v-model="scope.row.goodsCount" />
                    </template>
                  </el-table-column>
                  <el-table-column
                    :render-header="crud.renderHeader"
                    label="操作"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-button
                        class="el-icon-delete opration_icon_btn"
                        :disabled="
                          crud.order.orderStatus === 'PASS' ||
                            crud.order.orderStatus === 'INVALID'
                        "
                        style="border: none;width: auto;height: auto"
                        @click="delAddRow('giftList01', scope.$index)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
          </div>
          <div class="group" v-if="crud.order.type == 4">
            <el-row>
              <el-col :span="6">
                <el-form-item label="达成类型">
                  <el-select
                    v-model="crud.data.ruleList[0].reachType"
                    @change="pushInfo()"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_type"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="满减方式">
                  <el-select
                    v-model="crud.data.ruleList[0].reachWay"
                    @change="pushInfo(crud.data.reachWay)"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_way"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="满减方式" v-if="isShow">
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 1">
                  <div>
                    <el-checkbox v-model="checked" disabled>阶梯</el-checkbox>
                  </div>
                  <div class="flex-left">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >减</template
                        >
                      </el-input>
                      <img
                        src="@/assets/images/add@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS'"
                        @click="handleAdd"
                        style="width: 30px;cursor: pointer"
                      />
                      <img
                        src="@/assets/images/delete@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS' && index !== 0"
                        @click="handledel(index)"
                        style="width: 30px;cursor: pointer"
                      />
                    </div>
                  </div>
                </el-col>
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 2">
                  <div>
                    <el-checkbox v-model="checked" disabled>每满</el-checkbox>
                  </div>
                  <div class="flex-right">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >减</template
                        >
                      </el-input>
                      <!--                      <img src="@/assets/images/add@2x.png" @click="handleAdd" style="width: 30px;cursor: pointer">-->
                      <!--                      <img src="@/assets/images/delete@2x.png" v-if="index !==0" @click="handledel(index)"  style="width: 30px;cursor: pointer">-->
                    </div>
                  </div>
                </el-col>
              </el-form-item>
            </el-row>

            <div>
              <H3>活动商品列表</H3>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="toAdd"
              >
                新增
              </el-button>
            </div>
            <el-table
              ref="tableD"
              stripe
              border
              v-if="crud.order.type == 4"
              v-loading="crud.loading"
              :row-class-name="crud.tableRowClassName"
              :data="minusList || []"
              size="small"
              style="width: 100%;"
              :show-summary="true"
              sortable="custom"
              @sort-change="crud.sortChange"
              @selection-change="crud.selectionChangeHandler"
              @row-dblclick="crud.dbClick"
            >
              <el-table-column
                :render-header="crud.renderHeader"
                type="selection"
                width="60"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                type="index"
                width="60"
                label="序号"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsCode')"
                prop="goodsCode"
                label="商品编码"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsName')"
                prop="goodsName"
                label="商品名称"
                width="200"
              >
                <template slot-scope="scope">
                  <span v-if="!scope.row.isSelected">{{
                    scope.row.goodsName
                  }}</span>
                  <jtg-select-plus
                    v-else
                    ref="productRef"
                    v-model="scope.row.goodsId"
                    :initValue="scope.row.goodsName"
                    type="1"
                    :customerId="crud.order.customerId"
                    :buyChannel="crud.order.buyChannel"
                    @remoteMethod="getValue($event, scope.$index)"
                    @change="crud.productChange($event, scope)"
                    url="productList"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('helpSign')"
                prop="helpSign"
                label="助记符"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.helpSign }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('model')"
                prop="model"
                label="规格型号"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.model }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('barcode')"
                prop="barcode"
                label="条形码"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.barcode }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsBrandName')"
                prop="goodsBrandName"
                label="商品品牌"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.goodsBrandName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsTypeName')"
                prop="goodsTypeName"
                label="商品分类"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.goodsTypeName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('firstUnitName')"
                prop="firstUnitName"
                label="单位"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.firstUnitName }}</span>
                </template>
              </el-table-column>
              <el-table-column :render-header="crud.renderHeader" label="操作">
                <template slot-scope="scope">
                  <el-button
                    class="el-icon-delete opration_icon_btn"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    style="border: none;width: auto;height: auto"
                    @click="delAddRow('minusList', scope.$index)"
                  ></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="group" v-if="crud.order.type == 5">
            <el-row>
              <el-col :span="6">
                <el-form-item label="达成类型">
                  <el-select
                    v-model="crud.data.ruleList[0].reachType"
                    @change="pushInfo()"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_type"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="满折方式">
                  <el-select
                    v-model="crud.data.ruleList[0].reachWay"
                    @change="pushInfo"
                    class="edit-input"
                    placeholder="请选择"
                    style="width:  100%"
                  >
                    <el-option
                      v-for="(item, index) in dict.t_sales_promotion_reach_way"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-form-item label="满折方式" v-if="isShow">
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 1">
                  <div>
                    <el-checkbox v-model="checked" disabled>阶梯</el-checkbox>
                  </div>
                  <div class="flex-left">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >折</template
                        >
                      </el-input>
                      <img
                        src="@/assets/images/add@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS'"
                        @click="handleAdd"
                        style="width: 30px;cursor: pointer"
                      />
                      <img
                        src="@/assets/images/delete@2x.png"
                        v-if="crud.order.orderStatus !== 'PASS' && index !== 0"
                        @click="handledel(index)"
                        style="width: 30px;cursor: pointer"
                      />
                    </div>
                  </div>
                </el-col>
                <el-col :span="12" v-if="crud.data.ruleList[0].reachWay == 2">
                  <div>
                    <el-checkbox v-model="checked" disabled>每满</el-checkbox>
                  </div>
                  <div class="flex-right">
                    <div
                      class="flexs-cen"
                      v-for="(item, index) in crud.data.ruleList"
                    >
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.full"
                      >
                        <template slot="prepend"
                          >满</template
                        >
                      </el-input>
                      <el-input
                        style="width: 40%"
                        @input="changeInput"
                        placeholder="请输入"
                        v-model="item.result"
                      >
                        <template slot="prepend"
                          >折</template
                        >
                      </el-input>
                    </div>
                  </div>
                </el-col>
              </el-form-item>
            </el-row>
            <div>
              <H3>活动商品列表</H3>
              <el-button
                class="filter-item"
                size="mini"
                type="primary"
                @click="toAdd"
              >
                新增
              </el-button>
            </div>
            <el-table
              ref="tableE"
              stripe
              border
              v-if="crud.order.type == 5"
              v-loading="crud.loading"
              :row-class-name="crud.tableRowClassName"
              :data="discountList || []"
              size="small"
              style="width: 100%;"
              :show-summary="true"
              sortable="custom"
              @sort-change="crud.sortChange"
              @selection-change="crud.selectionChangeHandler"
              @row-dblclick="crud.dbClick"
            >
              <el-table-column
                :render-header="crud.renderHeader"
                type="selection"
                width="60"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                type="index"
                width="60"
                label="序号"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsCode')"
                prop="goodsCode"
                label="商品编码"
              />
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsName')"
                prop="goodsName"
                label="商品名称"
                width="200"
              >
                <template slot-scope="scope">
                  <span
                    v-if="
                      (!scope.row.isSelected &&
                        crud.order.orderStatus === 'PASS') ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    >{{ scope.row.goodsName }}</span
                  >
                  <jtg-select-plus
                    v-else
                    ref="productRef"
                    v-model="scope.row.goodsId"
                    type="1"
                    :customerId="crud.order.customerId"
                    :initValue="scope.row.goodsName"
                    :buyChannel="crud.order.buyChannel"
                    @remoteMethod="getValue($event, scope.$index)"
                    @change="crud.productChange($event, scope)"
                    url="productList"
                  />
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('helpSign')"
                prop="helpSign"
                label="助记符"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.helpSign }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('model')"
                prop="model"
                label="规格型号"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.model }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('barcode')"
                prop="barcode"
                label="条形码"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.barcode }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsBrandName')"
                prop="goodsBrandName"
                label="商品品牌"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.goodsBrandName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('goodsTypeName')"
                prop="goodsTypeName"
                label="商品分类"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.goodsTypeName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                v-if="columns.visible('firstUnitName')"
                prop="firstUnitName"
                label="单位"
              >
                <template slot-scope="scope">
                  <span>{{ scope.row.firstUnitName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :render-header="crud.renderHeader"
                label="操作"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    class="el-icon-delete opration_icon_btn"
                    :disabled="
                      crud.order.orderStatus === 'PASS' ||
                        crud.order.orderStatus === 'INVALID'
                    "
                    style="border: none;width: auto;height: auto"
                    @click="delAddRow('discountList', scope.$index)"
                  ></el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-row>
      </el-form>
      <j-dialog
        title="例外客户"
        v-dialogDrag
        isMask
        v-show="showExceptCustomer"
        :visible.sync="showExceptCustomer"
        style="width: 40%"
      >
        <div class="exceptCustomerBox">
          <j-dialog
            title="添加客户"
            v-dialogDrag
            isMask
            v-show="addExceptCustomer"
            :visible.sync="addExceptCustomer"
            style="width: 500px"
          >
            <zSelect
              @change="setExceptCustomer"
              :value.sync="exceptCustomer.customerId"
              url="api/dropDown/basCustomerList"
              style="width:  100%"
            />
            <div class="flex flex-reverse" style="width: 100%">
              <el-button @click="pushExceptCustomer">确定</el-button>
            </div>
          </j-dialog>
          <div>
            <el-button @click="addExceptCustomer = true">添加</el-button
            ><el-button @click="setCurrentImport('exceptCustomer')"
              >导入</el-button
            >
            <el-button size="small" type="info" @click="downloadTemplate"
              >下载模板
            </el-button>
          </div>
          <div
            v-for="item in crud.data.exceptCustomerList"
            class="exceptCustomer flex flex-row"
          >
            <div style="width:80%">
              {{ item.customerName }}
            </div>
            <div class="del" @click="removeExcept(item.customerId)">删除</div>
          </div>
        </div>
      </j-dialog>
      <j-dialog
        :title="currentImport.title"
        :visible.sync="isImport"
        style="width: 500px"
        zIndex="2002"
      >
        <el-upload
          class="upload-demo"
          :headers="headers"
          :on-error="handleError"
          :on-success="handleSuccess"
          :action="currentImport.action"
          multiple
          :limit="3"
        >
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
      </j-dialog>
      <!--分页组件-->
      <j-dialog
        title="客户群"
        v-dialogDrag
        isMask
        :visible.sync="showCustomerGroup"
        style="width: 40%"
      >
        <div class="exceptCustomerBox">
          <j-dialog
            title="添加客户"
            v-dialogDrag
            isMask
            :visible.sync="addCustomerGroup"
            style="width: 500px"
          >
            <zSelect
              @change="setCustomerGroup"
              :value.sync="exceptCustomer.customerId"
              url="api/dropDown/basCustomerList"
              style="width:  100%"
            />
            <div class="flex flex-reverse" style="width: 100%">
              <el-button @click="pushCustomerGroup">确定</el-button>
            </div>
          </j-dialog>
          <div>
            <el-button @click="addCustomerGroup = true">添加</el-button>
            <el-button @click="setCurrentImport('customerGroup')">
              导入</el-button
            >
            <el-button
              size="small"
              type="info"
              @click="downCustomerGroupTemplate"
              >下载模板
            </el-button>
          </div>
          <div
            v-for="(item, index) in crud.order.customerList"
            class="exceptCustomer flex flex-row"
          >
            <div style="width:80%">
              {{ item.customerName }}
            </div>
            <div class="del" @click="removeGroup(index)">删除</div>
          </div>
        </div>
      </j-dialog>
    </div>
  </div>
</template>

<script>
import crudSalesPromotion from "@/api/erp/salesPromotion";
import CRUD, { presenter, header, form, crud } from "@crud/crud";
import rrOperation from "@crud/RR.operation";
import crudOperation from "@crud/CRUD.operation";
import udOperation from "@crud/UD.operation";
import pagination from "@crud/Pagination";
import Treeselect from "@riophae/vue-treeselect";
import { getAreaTree } from "@/api/erp/basCustomerArea";
import { getDepts } from "@/api/system/dept";
import { getCustomerTypeTree } from "@/api/erp/basCustomerType";
import jtgSelectPlus from "@/components/select/JtgSelectPlusSale";
import JtgTree from "@/components/Tree/JtgTreePlus";
import Vue from "vue";
import { removeDetail } from "@/api/erp/salesPromotion";
import { passOrReject } from "../../../api/erp/salesPromotion";
import { getBasGoodsTagList } from "@/api/erp/basGoodsTag";
import jDialog from "@/components/jDialog/jDialog";
import { getToken } from "@/utils/auth";
import request from "@/utils/request";
import addBatch from "@/components/addBatch/addBatch.vue";
// crud交由presenter持有
const defaultCrud = CRUD({
  title: "促销明细",
  name: "salesPromotionDetail",
  url: "api/salesPromotion/detail",
  dicts: ["common_order_status", "t_sales_gift_list_gift_type"],
  sort: "id,desc",
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: false,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: true,
    reject: true
  },
  params() {
    const href = location.href.split("/");
    if (href[5].includes("copyId")) {
      return {
        id: 0
      };
    } else {
      return {
        id: href[href.length - 1] == "add" ? 0 : href[href.length - 1],
        page: 0,
        size: 999
      };
    }
  },
  crudMethod: { ...crudSalesPromotion }
});
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: 1,
  reach_way: null,
  reach_type: null,
  busDate: null,
  startDate: null,
  endDate: null,
  level: null,
  customerGroupType: null,
  customerId: null,
  customerCode: null,
  customerName: null,
  expenseRate: null,
  advanceRate: null,
  isContact: null,
  customerTypeId: null,
  customerTypeCode: null,
  customerTypeName: null,
  customerAreaId: null,
  customerAreaCode: null,
  customerAreaName: null,
  saleSystemId: null,
  saleSystemCode: null,
  saleSystemName: null,
  isLimitChannel: 0,
  channelType: null,
  isMutex: 1,
  schedule: null,
  oaCode: null,
  promotionProperties: null,
  ruleType: null,
  ruleWay: null,
  isRepeatJoin: 0,
  isLimitCount: 0,
  promotionLimitCount: null,
  promotionRemainCount: null,
  deptId: null,
  deptCode: null,
  deptName: null,
  userId: null,
  userCode: null,
  userName: null,
  seq: null,
  orderStatus: null,
  remark: null,
  orderRemark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null,
  auditUserId: null,
  auditUserCode: null,
  auditUserName: null,
  auditTime: null,
  closeUserId: null,
  closeUserCode: null,
  closeUserName: null,
  closeTime: null,
  invalidUserId: null,
  invalidUserCode: null,
  invalidUserName: null,
  invalidTime: null,

};
export default {
  name: "salesPromotionDetail",
  components: {
    addBatch,
    pagination,
    crudOperation,
    rrOperation,
    udOperation,
    Treeselect,
    JtgTree,
    jtgSelectPlus,
    jDialog
  },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: [
    "t_sales_promotion_type",
    "common_status",
    "t_sales_promotion_customer_group_type",
    "t_bas_customer_is_contact",
    "common_yes_or_no",
    "t_sales_promotion_channel_type",
    "t_sales_promotion_promotion_properties",
    "common_order_status",
    "t_sales_promotion_reach_type",
    "common_order_status",
    "t_bas_customer_channel_type",
    "t_sales_promotion_reach_way"
  ],
  data() {
    return {
      exceptCustomer: {
        customerId: null,
        customerCode: null,
        customerName: null,
        orderId: this.crud.order.id
      },
      importCustomer: {
        exceptCustomer: {
          title: "导入例外客户",
          action: "/api/salesPromotion/importExceptCustomer"
        },
        customerGroup: {
          title: "导入客户群",
          action: "/api/salesPromotion/importCustomerGroup"
        }
      },
      currentImport: {},
      addCustomerGroup: false,
      headers: { Authorization: getToken() },
      saleSystemIds: "",
      addExceptCustomer: "",
      customerTypeIds: [],
      customerAreaIds: [],
      showExceptCustomer: false,
      showCustomerGroup: false,
      currentCustomer: {},
      checked: true,
      isShow: true,
      dataExtent: [],
      minusList: [],
      specialList: [],
      exceptCustomerIds: [],
      saleSystemName: "",
      giftList: [],
      showAddBatch: false,
      resultList: [
        { label: "金额", value: 1 },
        { label: "数量", value: 2 },
        { label: "箱数", value: 3 }
      ],
      specialTypeList: [
        { label: "特价", value: 1 },
        { label: "秒杀", value: 2 }
      ],
      activityList: [],
      giftList01: [],
      isGiftTag: {},
      discountList: [],
      bomList: [],
      ruleList: [],
      activeName: "activity",
      permission: {
        add: ["admin", "salesPromotionDetail:add"],
        edit: ["admin", "salesPromotionDetail:edit"],
        del: ["admin", "salesPromotionDetail:del"],
        import: ["admin", "salesPromotionDetail:import"],
        export: ["admin", "salesPromotionDetail:export"],
        copy: ["admin", "salesPromotionDetail:copy"],
        upload: ["admin", "salesPromotionDetail:upload"],
        download: ["admin", "salesPromotionDetail:download"]
      },
      isImport: false,
      showAddBatchDialog: false,
      rules: {
        orderId: [
          { required: true, message: "库存记录id不能为空", trigger: "blur" }
        ],
        startDate: [
          { required: true, message: "开始日期不能为空", trigger: "blur" }
        ],
        customerGroupType: [
          { required: true, message: "客户群类型不能为空", trigger: "blur" }
        ],
        endDate: [
          { required: true, message: "结束日期不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "促销规则不能为空", trigger: "blur" }
        ],
        goodsId: [
          { required: true, message: "商品id不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "促销活动名称不能为空", trigger: "blur" }
        ],
        promotionSpecialType: [
          { required: true, message: "特价类型不能为空", trigger: "blur" }
        ]
      }
    };
  },
  watch: {},
  destroyed() {
    // Cookies.set("customerForm_" + this.id, JSON.stringify(this.form))
    if (!this.saveFlag) {
      this.crud.order.detailList = [
        {
          bomList: this.bomList || [],
          discountList: this.discountList || [],
          giftList: this.giftList || [],
          minusList: this.minusList || [],
          ruleList: this.ruleList || [],
          specialList: this.specialList || []
        }
      ];

      this.crud.setItemInfo("salesPromotionDetailAdd");
    }
  },
  handleError(err, file, fileList) {
    this.crud.notify(
      " -_- !~~ 服务器开小差了，稍后重试",
      CRUD.NOTIFICATION_TYPE.WARNING
    );
  },
  created() {
    const href = location.href.split("/");
    if (href[5].includes("copyId")) {
      let strs = this.$route.params.id.split("=");
      this.crud.toGetCopyInfo(strs[1], "salesPromotionDetail");
      this.crud.order.orderStatus = "SAVE";
    }
    if (this.$route.params.id == "add") {
      let _form = JSON.parse(localStorage.getItem("salesPromotionDetailAdd"));
      if (_form) {
        this.crud.order = _form;
        this.crud.data = _form.detailList;
        this.specialList = this.crud.data.specialList || [];
        this.minusList = this.crud.data.minusList || [];
        this.giftList = this.crud.data.giftList || [];
        this.discountList = this.crud.data.discountList || [];
        this.bomList = this.crud.data.bomList || [];
        this.ruleList = this.crud.data.ruleList || [];
        if (this.crud.data.ruleList.length === 0) {
          this.crud.data.ruleList = [
            {
              id: null,
              code: "",
              full: null,
              reachWay: null,
              reachType: null,
              result: null
            }
          ];
        } else {
          this.crud.data.reachType = this.crud.data.ruleList[0].reachType;
          this.crud.data.reachWay = this.crud.data.ruleList[0].reachWay;
          this.ruleList = this.crud.data.ruleList || [];
          console.log(this.crud.data.reachType);
        }
      } else {
        this.specialList = [];
        this.minusList = [];
        this.giftList = [];
        this.discountList = [];
        this.bomList = [];
        this.crud.data.ruleList = [
          {
            id: null,
            code: "",
            full: null,
            reachWay: null,
            reachType: null,
            result: null
          }
        ];
        this.crud.order = {
          id: null,
          code: null,
          name: null,
          type: 1,
          reachWay: null,
          customerGroupTypeName: null,
          reachType: null,
          busDate: this.getTime(),
          startDate: this.getTime(),
          endDate: null,
          level: null,
          channel: null,
          customerGroupType: null,
          customerId: null,
          customerCode: null,
          customerName: null,
          isContact: null,
          customerTypeId: null,
          customerTypeCode: null,
          customerTypeName: null,
          customerAreaId: null,
          customerAreaCode: null,
          customerAreaName: null,
          saleSystemId: null,
          saleSystemCode: null,
          saleSystemName: null,
          isLimitChannel: 0,
          channelType: null,
          isMutex: 1,
          schedule: null,
          oaCode: null,
          promotionProperties: null,
          ruleType: null,
          ruleWay: null,
          isRepeatJoin: 0,
          isLimitCount: 0,
          promotionLimitCount: null,
          promotionRemainCount: null,
          deptId: null,
          deptCode: null,
          deptName: null,
          userId: null,
          userCode: null,
          userName: null,
          seq: null,
          orderStatus: null,
          remark: null,
          orderRemark: null,
          createUserId: null,
          createUserCode: null,
          createUserName: null,
          createTime: null,
          updateUserId: null,
          updateUserCode: null,
          updateUserName: null,
          updateTime: null,
          auditUserId: null,
          auditUserCode: null,
          auditUserName: null,
          auditTime: null,
          closeUserId: null,
          closeUserCode: null,
          closeUserName: null,
          closeTime: null,
          invalidUserId: null,
          invalidUserCode: null,
          invalidUserName: null,
          invalidTime: null
        };
      }
    }
    getBasGoodsTagList({ size: 999 }).then(res => {
      this.isGiftTag = res.content.find(
        item => item.name === "赠品" || item.name === "促销酒"
      );
    });
  },
  mounted() {},
  // updated() {
  //   this.$nextTick(() => {
  //     this.$refs.table.doLayout()
  //   })},
  methods: {
    changeInfo(e) {},
    setResultType(index, e) {
      this.$forceUpdate();
    },
    setCurrentImport(type) {
      this.currentImport = this.importCustomer[type];
      this.isImport = true;
    },
    handleError(err, file, fileList) {
      this.crud.notify(
        " -_- !~~ 服务器开小差了，稍后重试",
        CRUD.NOTIFICATION_TYPE.WARNING
      );
    },
    downloadTemplate() {
      request({
        url: "api/common/downloadExcelTemplate?name=促销例外客户.xlsx",
        method: "get",
        responseType: "blob"
      }).then(res => {
        const a = document.createElement("a");
        const blob = new Blob([res], {
          type: "application/vnd.ms-excel"
        });
        const objectUrl = URL.createObjectURL(blob);
        a.setAttribute("href", objectUrl);
        a.setAttribute("download", "促销例外客户.xlsx");
        a.click();
      });
    },
    downCustomerGroupTemplate() {
      request({
        url: "api/common/downloadExcelTemplate?name=促销客户群.xlsx",
        method: "get",
        responseType: "blob"
      }).then(res => {
        const a = document.createElement("a");
        const blob = new Blob([res], {
          type: "application/vnd.ms-excel"
        });
        const objectUrl = URL.createObjectURL(blob);
        a.setAttribute("href", objectUrl);
        a.setAttribute("download", "客户群.xlsx");
        a.click();
      });
    },
    tabSelect(row) {
      if (this.crud.order.orderStatus !== "PASS") {
        this.$set(row, "isSelected", !row.isSelected);
      }
    },
    handleSuccess(response, file, fileList) {
      console.log("handleSuccess", response);
      if (response !== "导入成功") {
        const a = document.createElement("a");
        a.setAttribute("href", response.data.result);
        a.click();
      } else {
        this.crud.notify(response, CRUD.NOTIFICATION_TYPE.SUCCESS);
        this.$refs.upload.clearFiles();
        this.uploadDialgShow = false;
        this.crud.refresh();
      }
    },
    delAddRow(name, i) {
      const id = this[name][i].id;
      const that = this;
      if (id) {
        removeDetail({ id, type: this.crud.order.type }).then(res => {
          if (res.status === 200) {
            that[name].splice(i, 1);
          } else {
            this.$message({
              type: "error",
              message: res.msg
            });
          }
        });
      } else {
        that[name].splice(i, 1);
      }
    },
    pushInfo(e) {
      if (e === 2) {
        this.$set(this.crud.data.ruleList, "0", this.crud.data.ruleList[0]);
      }
      this.$forceUpdate();
      this.isShow = true;
    },
    getTime(date = new Date()) {
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;
      var second = date.getSeconds();
      second = second < 10 ? "0" + second : second;
      // +' '+h+':'+minute+':'+second;
      return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.afterRefresh]() {
      setTimeout(() => {
        this.specialList = this.crud.data.specialList || [];
        this.minusList = this.crud.data.minusList || [];
        this.giftList = this.crud.data.giftList || [];
        this.discountList = this.crud.data.discountList || [];
        this.bomList = this.crud.data.bomList || [];
        this.ruleList = this.crud.data.ruleList || [];
        this.giftList01 = [];
        this.activityList = [];
        if (this.crud.data.giftList) {
          for (let i = 0; i < this.crud.data.giftList.length; i++) {
            if (this.crud.data.giftList[i].isGift) {
              this.giftList01.push(this.crud.data.giftList[i]);
            } else {
              this.activityList.push(this.crud.data.giftList[i]);
            }
          }
        }
        if (this.crud.order.exceptCustomerIds)
          this.exceptCustomerIds = this.crud.order.exceptCustomerIds.split(",");
        if (this.crud.order.customerTypeList)
          this.customerTypeIds = this.crud.order.customerTypeList.map(
            item => item.customerTypeId
          );
        if (this.crud.order.customerAreaList)
          this.customerAreaIds = this.crud.order.customerAreaList.map(
            item => item.customerAreaId
          );
        if (this.crud.order.saleSystemList) {
          this.saleSystemIds = this.crud.order.saleSystemList
            .map(item => item.saleSystemId)
            .join(",");
          this.saleSystemName = this.crud.order.saleSystemList
            .map(item => item.saleSystemName)
            .join(",");
        }
      });
      return true;
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {},
    getValue(e) {
      this.query.startTime = this.dataExtent[0];
      this.query.endTime = this.dataExtent[1];
    },
    getInput(e, name, i) {
      if (this.crud.data) {
        if (e) {
          this.crud.data[i].goodsName = "";
          this.crud.data[i].goodsId = e;
        } else {
          this.crud.data[i].goodsName = "";
          this.crud.data[i].goodsId = null;
        }
      }
    },
    addBatchGoods(list) {
      list.forEach(item => {
        //去重
        if (this.activeName === "activity") {
          const index = this.activityList.some(
            val => item.goodsId === val.goodsId
          );
          if (!index) {
            item.isRequired = 0;
            const goods = Object.assign(
              {
                isSelected: false,
                isGift: 0,
                id: null,
                saleTaxPrice: null,
                promotionTaxPrice: 0,
                goodsCount: 0,
                orderId: null,
                goodsId: null,
                goodsCode: null,
                goodsName: null,
                barcode: null,
                boxBarcode: null,
                helpSign: null,
                model: null,
                goodsBrandId: null,
                goodsBrandCode: null,
                goodsBrandName: null,
                goodsTypeId: null,
                goodsTypeCode: null,
                goodsTypeName: null,
                goodsTagId: null,
                goodsTagCode: null,
                goodsTagName: null,
                taxId: null,
                taxCode: null,
                taxName: null,
                taxRate: null,
                firstUnitId: null,
                firstUnitCode: null,
                firstUnitName: null,
                firstUnitCount: null,
                effectGoodsCount: null,
                cutOffGoodsCount: null,
                taxPrice: null,
                noTaxPrice: null,
                taxBoxPrice: null,
                noTaxBoxPrice: null,
                seq: null,
                remark: null,
                createUserId: null,
                createUserCode: null,
                createUserName: null,
                createTime: null,
                updateUserId: null,
                updateUserCode: null,
                updateUserName: null,
                updateTime: null,
                isRequired: 0
              },
              item
            );
            this.toAdd(goods);
          }
        } else {
          const index = this.giftList01.some(
            val => item.goodsId === val.goodsId
          );
          if (!index) {
            item.isRequired = 0;
            const goods = Object.assign(
              {
                isSelected: false,
                isGift: 1,
                id: null,
                saleTaxPrice: null,
                promotionTaxPrice: 0,
                goodsCount: 0,
                orderId: null,
                goodsId: null,
                goodsCode: null,
                goodsName: null,
                barcode: null,
                boxBarcode: null,
                helpSign: null,
                model: null,
                goodsBrandId: null,
                goodsBrandCode: null,
                goodsBrandName: null,
                goodsTypeId: null,
                goodsTypeCode: null,
                goodsTypeName: null,
                goodsTagCode: null,
                goodsTagName: null,
                taxId: null,
                taxCode: null,
                taxName: null,
                taxRate: null,
                firstUnitId: null,
                firstUnitCode: null,
                firstUnitName: null,
                firstUnitCount: null,
                effectGoodsCount: null,
                cutOffGoodsCount: null,
                taxPrice: null,
                noTaxPrice: null,
                taxBoxPrice: null,
                noTaxBoxPrice: null,
                seq: null,
                remark: null,
                createUserId: null,
                createUserCode: null,
                createUserName: null,
                createTime: null,
                updateUserId: null,
                updateUserCode: null,
                updateUserName: null,
                updateTime: null,
                isGiftPaperBox: 0,
                goodsTagId: null,
                advanceRate: this.crud.order.advanceRate,
                expenseRate: this.crud.order.expenseRate
              },
              item
            );
          }
        }
      });
    },
    afterChangeGoods(goods) {
      this.showAddBatchDialog = false;
      //去重，已经去重
      let arr = this.crud.data.map(detail => detail.goodsId);
      let _goods = [];
      let result = [];
      goods.forEach(good => {
        // if(!arr.includes(goods.goodsId)){
        good.isSelected = true;
        this.crud.data.push(good);
        // }
      });
      // this.calcuForm()
    },
    changeRate(type) {
      if (Number(this.crud.order[type]) > 100) {
        this.$message.error("比例不允许大于100");
        this.crud.order[type] = 100;
      }
      if (type === "advanceRate") {
        const expenseRate = 100 - Number(this.crud.order.advanceRate);
        this.$set(this.crud.order, "expenseRate", expenseRate);
      } else {
        const advanceRate = 100 - Number(this.crud.order.expenseRate);
        this.$set(this.crud.order, "advanceRate", advanceRate);
      }
    },
    setExceptCustomer(e) {
      this.exceptCustomer.customerId = e.id;
      this.exceptCustomer.customerCode = e.code;
      this.exceptCustomer.customerName = e.name;
    },
    setCustomerGroup(e) {
      this.currentCustomer.customerId = e.id;
      this.currentCustomer.customerCode = e.code;
      this.currentCustomer.customerName = e.name;
    },
    toAddList() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          //校验通过
          this.showAddBatchDialog = true;
        } else {
          // if (!this.crud.order.customerId) {
          //   this.$message.error("请先选择客户")
          // }
          // if (!this.crud.order.type) {
          //   this.$message.error("请先选择销售单类型")
          // }
        }
      });
    },
    getInfo(e) {
      this.crud.order.warehouseId = e.warehouseId;
      this.crud.order.deptId = e.deptId;
      this.crud.order.userId = e.userId;

      this.crud.order.carId = e.carId;
      this.crud.order.loadCode = e.loadCode;
      this.crud.order.loadTime = e.loadTime;

      this.crud.order.driverUserId = e.driverUserId;
      this.crud.order.followUserId = e.followUserId;
      this.crud.order.printStatus = e.printStatus;

      this.crud.order.printCount = e.printCount;
      this.crud.order.acceptStatus = e.acceptStatus;
      this.crud.order.cancelStatus = e.cancelStatus;
      this.crud.order.pickSeq = e.pickSeq;
      this.crud.order.warehouseId = e.warehouseId;
      this.crud.order.contactName = e.contactName;
      this.crud.order.contactPhone = e.contactPhone;
      this.crud.order.deliveryAddress = e.deliveryAddress;
      this.crud.order.address = e.address;
    },
    // 新增
    toAdd(e) {
      // if(!this.crud.order.customerId){
      //   this.$message({
      //     message: '请先选择客户',
      //     type: 'error'
      //   })
      //   return false
      // }
      if (!e.goodsId) e = null;
      this.$nextTick(() => {
        if (this.crud.order.type == 1) {
          this.specialList.push(
            e || {
              isSelected: true,
              id: null,
              promotionTaxPrice: 0,
              goodsCount: 0,
              saleTaxPrice: null,
              orderId: null,
              goodsId: null,
              goodsCode: null,
              goodsName: null,
              barcode: null,
              boxBarcode: null,
              helpSign: null,
              model: null,
              goodsBrandId: null,
              goodsBrandCode: null,
              goodsBrandName: null,
              goodsTypeId: null,
              goodsTypeCode: null,
              goodsTypeName: null,
              goodsTagId: null,
              goodsTagCode: null,
              goodsTagName: null,
              taxId: null,
              taxCode: null,
              taxName: null,
              taxRate: null,
              firstUnitId: null,
              firstUnitCode: null,
              firstUnitName: null,
              firstUnitCount: null,
              effectGoodsCount: null,
              cutOffGoodsCount: null,
              taxPrice: null,
              noTaxPrice: null,
              taxBoxPrice: null,
              noTaxBoxPrice: null,
              seq: null,
              remark: null,
              createUserId: null,
              createUserCode: null,
              createUserName: null,
              createTime: null,
              updateUserId: null,
              updateUserCode: null,
              updateUserName: null,
              updateTime: null,
              promotionTaxBoxPrice: null
            }
          );
        } else if (this.crud.order.type == 2) {
          this.bomList.push(
            e || {
              isSelected: true,
              id: null,
              saleTaxPrice: null,
              promotionTaxPrice: 0,
              goodsCount: 0,
              orderId: null,
              goodsId: null,
              goodsCode: null,
              goodsName: null,
              barcode: null,
              boxBarcode: null,
              helpSign: null,
              model: null,
              goodsBrandId: null,
              goodsBrandCode: null,
              goodsBrandName: null,
              goodsTypeId: null,
              goodsTypeCode: null,
              goodsTypeName: null,
              goodsTagId: null,
              goodsTagCode: null,
              goodsTagName: null,
              taxId: null,
              taxCode: null,
              taxName: null,
              taxRate: null,
              firstUnitId: null,
              firstUnitCode: null,
              firstUnitName: null,
              firstUnitCount: null,
              effectGoodsCount: null,
              cutOffGoodsCount: null,
              taxPrice: null,
              noTaxPrice: null,
              taxBoxPrice: null,
              noTaxBoxPrice: null,
              seq: null,
              remark: null,
              createUserId: null,
              createUserCode: null,
              createUserName: null,
              createTime: null,
              updateUserId: null,
              updateUserCode: null,
              updateUserName: null,
              updateTime: null
            }
          );
        } else if (this.crud.order.type == 3) {
          if (this.activeName === "activity") {
            this.activityList.push(
              e || {
                isSelected: true,
                isGift: 0,
                id: null,
                saleTaxPrice: null,
                promotionTaxPrice: 0,
                goodsCount: 0,
                orderId: null,
                goodsId: null,
                goodsCode: null,
                goodsName: null,
                barcode: null,
                boxBarcode: null,
                helpSign: null,
                model: null,
                goodsBrandId: null,
                goodsBrandCode: null,
                goodsBrandName: null,
                goodsTypeId: null,
                goodsTypeCode: null,
                goodsTypeName: null,
                goodsTagId: null,
                goodsTagCode: null,
                goodsTagName: null,
                taxId: null,
                taxCode: null,
                taxName: null,
                taxRate: null,
                firstUnitId: null,
                firstUnitCode: null,
                firstUnitName: null,
                firstUnitCount: null,
                effectGoodsCount: null,
                cutOffGoodsCount: null,
                taxPrice: null,
                noTaxPrice: null,
                taxBoxPrice: null,
                noTaxBoxPrice: null,
                seq: null,
                remark: null,
                createUserId: null,
                createUserCode: null,
                createUserName: null,
                createTime: null,
                updateUserId: null,
                updateUserCode: null,
                updateUserName: null,
                updateTime: null,
                isRequired: 0
              }
            );
          } else {
            this.giftList01.push(
              e || {
                isSelected: true,
                isGift: 1,
                id: null,
                saleTaxPrice: null,
                promotionTaxPrice: 0,
                goodsCount: 0,
                orderId: null,
                goodsId: null,
                goodsCode: null,
                goodsName: null,
                barcode: null,
                boxBarcode: null,
                helpSign: null,
                model: null,
                goodsBrandId: null,
                goodsBrandCode: null,
                goodsBrandName: null,
                goodsTypeId: null,
                goodsTypeCode: null,
                goodsTypeName: null,
                goodsTagCode: null,
                goodsTagName: null,
                taxId: null,
                taxCode: null,
                taxName: null,
                taxRate: null,
                firstUnitId: null,
                firstUnitCode: null,
                firstUnitName: null,
                firstUnitCount: null,
                effectGoodsCount: null,
                cutOffGoodsCount: null,
                taxPrice: null,
                noTaxPrice: null,
                taxBoxPrice: null,
                noTaxBoxPrice: null,
                seq: null,
                remark: null,
                createUserId: null,
                createUserCode: null,
                createUserName: null,
                createTime: null,
                updateUserId: null,
                updateUserCode: null,
                updateUserName: null,
                updateTime: null,
                isGiftPaperBox: 0,
                goodsTagId: null,
                advanceRate: this.crud.order.advanceRate,
                expenseRate: this.crud.order.expenseRate
              }
            );
          }
        } else if (this.crud.order.type == 4) {
          this.minusList.push(
            e || {
              isSelected: true,
              id: null,
              saleTaxPrice: null,
              promotionTaxPrice: 0,
              goodsCount: 0,
              orderId: null,
              goodsId: null,
              goodsCode: null,
              goodsName: null,
              barcode: null,
              boxBarcode: null,
              helpSign: null,
              model: null,
              goodsBrandId: null,
              goodsBrandCode: null,
              goodsBrandName: null,
              goodsTypeId: null,
              goodsTypeCode: null,
              goodsTypeName: null,
              goodsTagId: null,
              goodsTagCode: null,
              goodsTagName: null,
              taxId: null,
              taxCode: null,
              taxName: null,
              taxRate: null,
              firstUnitId: null,
              firstUnitCode: null,
              firstUnitName: null,
              firstUnitCount: null,
              effectGoodsCount: null,
              cutOffGoodsCount: null,
              taxPrice: null,
              noTaxPrice: null,
              taxBoxPrice: null,
              noTaxBoxPrice: null,
              seq: null,
              remark: null,
              createUserId: null,
              createUserCode: null,
              createUserName: null,
              createTime: null,
              updateUserId: null,
              updateUserCode: null,
              updateUserName: null,
              updateTime: null
            }
          );
        } else if (this.crud.order.type == 5) {
          this.discountList.push(
            e || {
              isSelected: true,
              id: null,
              saleTaxPrice: null,
              promotionTaxPrice: 0,
              goodsCount: 0,
              orderId: null,
              goodsId: null,
              goodsCode: null,
              goodsName: null,
              barcode: null,
              boxBarcode: null,
              helpSign: null,
              model: null,
              goodsBrandId: null,
              goodsBrandCode: null,
              goodsBrandName: null,
              goodsTypeId: null,
              goodsTypeCode: null,
              goodsTypeName: null,
              goodsTagId: null,
              goodsTagCode: null,
              goodsTagName: null,
              taxId: null,
              taxCode: null,
              taxName: null,
              taxRate: null,
              firstUnitId: null,
              firstUnitCode: null,
              firstUnitName: null,
              firstUnitCount: null,
              effectGoodsCount: null,
              cutOffGoodsCount: null,
              taxPrice: null,
              noTaxPrice: null,
              taxBoxPrice: null,
              noTaxBoxPrice: null,
              seq: null,
              remark: null,
              createUserId: null,
              createUserCode: null,
              createUserName: null,
              createTime: null,
              updateUserId: null,
              updateUserCode: null,
              updateUserName: null,
              updateTime: null
            }
          );
        }
      });
    },
    productChange($event, scope) {
      $event.goodsTagId = this.isGiftTag.id;
      $event.goodsTagName = this.isGiftTag.name;
      $event.goodsTagCode = this.isGiftTag.code;
      this.crud.productChange($event, scope);
    },
    submit() {
      let that = this;
      try {
        this.$refs["form"].validate(valid => {
          if (!valid) {
            return;
          }
          that.crud.loadingOpen();
          if (this.crud.order.type === 3) {
            if (!this.activityList.length || !this.giftList01.length) {
              this.$message({
                type: "error",
                message: "满赠属性活动商品和赠品不能为空"
              });
              that.crud.loadingClose();
              return;
            }
          }
          if (this.exceptCustomerIds.length) {
            this.crud.order.exceptCustomerIds = this.exceptCustomerIds.join(
              ","
            );
          }
          // this.crud.order.customerTypeIds = this.customerTypeIds.length?this.customerTypeIds.join(','):''
          // this.crud.order.customerAreaIds = this.customerAreaIds.length?this.customerAreaIds.join(','):''
          // this.crud.order.saleSystemIds = this.saleSystemIds.length?this.saleSystemIds.join(','):''
          this.crud.order.customerTypeList = this.customerTypeIds.map(item => {
            return { customerTypeId: item };
          });
          this.crud.order.customerAreaList = this.customerAreaIds.map(item => {
            return { customerAreaId: item };
          });
          if (this.saleSystemIds)
            this.crud.order.saleSystemList = this.saleSystemIds
              .split(",")
              .map(item => {
                return { saleSystemId: item };
              });

          this.crud.order.detailList = [
            {
              bomList: this.bomList || [],
              discountList: this.discountList || [],
              giftList: [...this.activityList, ...this.giftList01],
              minusList: this.minusList || [],
              ruleList: this.crud.data.ruleList || [],
              specialList: this.specialList || [],
              exceptCustomerList: this.crud.data.exceptCustomerList || []
            }
          ];

          if (this.crud.data.ruleList) {
            this.crud.data.ruleList.forEach(item => {
              item.reachWay = this.crud.data.ruleList[0].reachWay;
              item.reachType = this.crud.data.ruleList[0].reachType;
            });
          }
          let params = this.crud.order;
          crudSalesPromotion
            .add(params)
            .then(res => {
              if (res.success) {
                this.crud.order = res.data;
                // this.crud.data = res.data.detailList
                let id = res.data.id;
                if (this.$route.params.id == "add") {
                  this.$store.dispatch("tagsView/delView", this.$route);
                  this.$router.push({ params: { id } });
                  this.crud.cleanItemInfo("salesPromotionDetailAdd");
                }
                // this.crud.refresh()
                this.$message({
                  message: "保存成功",
                  type: "success"
                });
                that.crud.loadingClose();
                const oldId = window.location.href.split("/").slice(-1)[0];
                if (oldId.includes("copyId")) {
                  const p = new Promise((resolve, reject) => {
                    setTimeout(() => {
                      this.cancel(oldId);
                      resolve(res.data.id);
                    }, 10);
                  });
                  p.then(val => {
                    setTimeout(() => {
                      this.$router.push("/sale/salesPromotionDetail/" + val);
                    });
                  });
                } else {
                  this.crud.refresh();
                }
              } else {
                that.crud.loadingClose();
                this.$message({
                  message: res.msg,
                  type: "warning"
                });
              }
            })
            .catch(res => {
              that.crud.loadingClose();
            });
        });
      } catch (e) {
        console.log(e);
        that.crud.loadingClose();
      }
    },

    cancel(id) {
      this.$store
        .dispatch("tagsView/delView", {
          path: "/sale/salesPromotionDetail/" + id
        })
        .then(({ visitedViews }) => {
          this.saveFlag = true;
          const latestView = visitedViews.slice(-1)[0];
          if (latestView) {
            this.$router.push(latestView);
          } else {
          }
        });
    },
    pushExceptCustomer() {
      if (!this.crud.data.exceptCustomerList)
        this.crud.data.exceptCustomerList = [];
      const index = this.crud.data.exceptCustomerList.findIndex(
        item => item.customerId === this.exceptCustomer.customerId
      );
      console.log(this.crud.data.exceptCustomerList);
      console.log(index);
      if (index !== -1) {
        this.$message.error("该客户已存在");
        return;
      }
      this.crud.data.exceptCustomerList.push(
        Object.assign({}, this.exceptCustomer)
      );
      console.log(this.crud.data.exceptCustomerList);
      this.exceptCustomer.customerId = null;
      this.exceptCustomer.customerCode = null;
      this.exceptCustomer.customerName = null;
      this.$message.success("添加成功");
    },
    pushCustomerGroup() {
      if (this.currentCustomer.customerId === null)
        return this.$message.error("请先选择客户");
      if (!this.crud.order.customerList)
        this.$set(this.crud.order, "customerList", []);
      const index = this.crud.order.customerList.findIndex(
        item => item.customerId === this.currentCustomer.customerId
      );
      if (~index) return this.$message.error("该客户已存在");
      this.crud.order.customerList.push(
        Object.assign({}, this.currentCustomer)
      );
      this.currentCustomer.customerId = null;
      this.currentCustomer.customerCode = null;
      this.currentCustomer.customerName = null;
      this.$message.success("添加成功");
    },
    isNum(item, index) {
      item.full =
        index > 0
          ? item.full > this.ruleList[index - 1].full
            ? item.full
            : Number(this.ruleList[index - 1].full) + 1
          : item.full;
    },
    isGiftNum(item, index) {
      item.result =
        index > 0
          ? item.result > this.ruleList[index - 1].result
            ? item.result
            : Number(this.ruleList[index - 1].result) + 1
          : item.result;
    },
    inputCount(scope, type) {
      if (type === "promotionTaxPrice") {
        const promotionTaxBoxPrice = (
          Number(scope.row.promotionTaxPrice) * Number(scope.row.boxUnitCount)
        ).toFixed(2);
        scope.row.promotionNoTaxPrice =
          scope.row.promotionTaxPrice / (1 + scope.row.taxRate / 100);
        scope.row.promotionNoTaxBoxPrice =
          Number(scope.row.promotionNoTaxPrice) *
          Number(scope.row.boxUnitCount);
        this.$set(scope.row, "promotionTaxBoxPrice", promotionTaxBoxPrice);
        console.log(scope.row.promotionTaxBoxPrice);
      } else if (type === "promotionTaxBoxPrice") {
        scope.row.promotionTaxPrice = (
          Number(scope.row.promotionTaxBoxPrice) /
          Number(scope.row.boxUnitCount)
        ).toFixed(2);
        scope.row.promotionNoTaxPrice =
          scope.row.promotionTaxPrice / (1 + scope.row.taxRate / 100);
        scope.row.promotionNoTaxBoxPrice =
          Number(scope.row.promotionNoTaxPrice) *
          Number(scope.row.boxUnitCount);
      }
      this.$forceUpdate();
    },
    changeInput(val) {
      this.$forceUpdate();
    },
    removeExcept(id) {
      const index = this.crud.data.exceptCustomerList.findIndex(
        item => item.customerId === id
      );
      this.crud.data.exceptCustomerList.splice(index, 1);
    },
    removeGroup(index) {
      // const index = this.crud.order.customerList.findIndex(item=>item.customerId === id)
      console.log(this.crud.order.customerList, index);
      this.crud.order.customerList.splice(index, 1);
    },
    handleAdd() {
      this.isShow = false;
      this.$nextTick(() => {
        this.isShow = true;
        let that = this;
        console.log(" this.crud.data", this.crud.data);
        let data = {
          id: null,
          code: "",
          full: null,
          reach_way: null,
          reach_type: null,
          result: null
        };
        that.crud.data.ruleList.push(data);
        let leit = JSON.stringify(that.ruleList);
        that.ruleList = JSON.parse(leit);
      });
    },
    recover(type) {
      const that = this;
      crudSalesPromotion
        .passOrReject({ ids: [this.crud.order.id], type: type })
        .then(res => {
          if (res.status === 200) {
            that.$message.success("操作成功");
            that.crud.refresh();
          }
        });
    },
    handledel(index) {
      this.isShow = false;
      let that = this;
      console.log(that);
      this.$nextTick(() => {
        this.isShow = true;
        that.crud.data.ruleList.splice(index, 1);
        that.ruleList.splice(index, 1);
        let leit = JSON.stringify(that.ruleList);
        that.ruleList = JSON.parse(leit);
      });
    },

    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      };
    }
  }
};
</script>

<style lang="scss" scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
.flex-left {
  display: inline-block;
}
.flex-right {
  display: inline-block;
}
.flexs-cen {
  display: flex;
  height: 40px;
  line-height: 40px;
  align-items: center;
  justify-content: space-between;
}
.exceptCustomerBox {
  height: 500px;
  overflow: auto;
  .exceptCustomer {
    font-size: 20px;
    margin-top: 10px;
    .del {
      color: blue;
      cursor: pointer;
    }
  }
}
</style>
